package com.cskaoyan.controller;


import com.cskaoyan.bean.baseresultVO.BaseData;
import com.cskaoyan.bean.baseresultVO.BaseParam;
import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.domain.Topic;
import com.cskaoyan.bean.topic.TopicBatchDeleteBO;
import com.cskaoyan.bean.topic.TopicReadVO;
import com.cskaoyan.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 专题表 前端控制器
 * </p>
 *
 * @author looper
 * @since 2021-11-29
 */
@RestController
@RequestMapping("/admin/topic")
public class TopicController {
    @Autowired
    TopicService topicService;

    @RequestMapping("list")
    public BaseRespVo<BaseData> topicList(String title, String subtitle, BaseParam baseParam) {
        BaseData baseData = topicService.topicList(title, subtitle, baseParam);
        return BaseRespVo.ok(baseData);
    }

    @GetMapping("read")
    public BaseRespVo<TopicReadVO> read(Integer id) {
        TopicReadVO topicReadVO = topicService.read(id);
        return BaseRespVo.ok(topicReadVO);
    }

    @PostMapping("update")
    public BaseRespVo<Topic> topicUpdate(@RequestBody @Valid Topic topic) {
        Topic topic1 = topicService.topicUpdate(topic);
        return BaseRespVo.ok(topic1);
    }

    @PostMapping("delete")
    public BaseRespVo topicDelete(@RequestBody Topic topic) {
        int affectedRow = topicService.topicDelete(topic);
        return BaseRespVo.ok(affectedRow);
    }

    @PostMapping("batch-delete")
    public BaseRespVo topicBatchDelete(@RequestBody TopicBatchDeleteBO batchDeleteBO) {
        int affectedRow = topicService.topicBatchDelete(batchDeleteBO);
        return BaseRespVo.ok(affectedRow);
    }

    @PostMapping("create")
    public BaseRespVo<Topic> topicCreate(@RequestBody @Valid Topic topic) {
        Topic topic1 = topicService.topicCreate(topic);
        return BaseRespVo.ok(topic1);
    }

}

